package com.example.tys.baseapplication.NetModel.executor.rxandroid;

import android.util.Log;
import android.widget.Toast;

import com.example.tys.baseapplication.MyApp;

import io.reactivex.annotations.NonNull;
import io.reactivex.observers.ResourceObserver;

/**
 * Created by tys on 2017/10/11.
 */

public class BaseResourceObserver<T> extends ResourceObserver<T> {

    private static final String TAG = "BaseResourceObserver";

    @Override
    protected void onStart() {
        super.onStart();
        start();
    }

    protected void start() {

    }

    @Override
    public void onNext(@NonNull T result) {
        success(result);
    }

    protected void success(T response) {
    }

    @Override
    public void onComplete() {
        complete();
    }

    protected void complete() {

    }


    @Override
    public void onError(@NonNull Throwable e) {
        error(e);
    }

    protected void error(Throwable e) {
        //UI 线程异常统一处理
        Log.e(TAG, e.toString());
        Toast.makeText(MyApp.getInstance(),e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}
